package com.dogsong.liteflow.editor.util;

import com.yomahub.liteflow.parser.constant.ReadType;
import com.yomahub.liteflow.parser.sql.read.SqlRead;
import com.yomahub.liteflow.parser.sql.read.SqlReadFactory;
import com.yomahub.liteflow.parser.sql.read.impl.ChainRead;
import com.yomahub.liteflow.parser.sql.read.vo.ChainVO;
import com.yomahub.liteflow.parser.sql.util.LiteFlowJdbcUtil;
import com.yomahub.liteflow.parser.sql.vo.SQLParserVO;

import java.sql.Connection;

/**
 * sql连接工厂
 *
 * @author: Young
 * @date: 2024/12/17
 */
public class SqlConnectFactory {

    public static SQLParserVO getSqlConfig(){
        return SqlConfigHolder.config;
    }

    public static Connection getConn(){
        return LiteFlowJdbcUtil.getConn(SqlConnectFactory.getSqlConfig());
    }

    private static class SqlConfigHolder{
        public static SQLParserVO config;

        static {
            SqlRead<ChainVO> sqlRead = SqlReadFactory.getSqlRead(ReadType.CHAIN);
            ChainRead chainRead = (ChainRead) sqlRead;
            config = chainRead.config;
        }
    }
}
